package example

import (
	"fmt"
	"jslog/system/config"
	"os"

	"github.com/spf13/viper"
)

func Viper(cfg *config.Server) *viper.Viper {
	workDir, err := os.Getwd()
	if err != nil {
		panic(fmt.Errorf("Fatal error Item file: %s \n", err))
	}
	v := viper.New()
	v.SetConfigFile(workDir + "/config.yaml")
	v.SetConfigType("yaml")
	err = v.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
	v.WatchConfig()
	if err = v.Unmarshal(cfg); err != nil {
		panic(err)
	}
	return v
}
